package thread;

public class LockSupport {

    Thread t1 = null;
    Thread t2 = null;

    public void merge() {
        char[] number = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};
        char[] letter = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};

        t1 = new Thread(() -> {
            for (char num : number) {
                System.out.print(num + " ");
                java.util.concurrent.locks.LockSupport.unpark(t2);  //唤醒t2线程
                java.util.concurrent.locks.LockSupport.park();  //将本线程阻塞
            }
        });

        t2 = new Thread(() -> {
            for (char let : letter) {
                java.util.concurrent.locks.LockSupport.park();  //防止t2线程先执行从而先输出A
                System.out.print(let + " ");
                java.util.concurrent.locks.LockSupport.unpark(t1);  //唤醒t1线程
            }
        });

        t1.start();
        t2.start();
    }

    public static void main(String[] args) {
        LockSupport test = new LockSupport();
        test.merge();
    }
}
